﻿using System;
using System.ComponentModel;

namespace UpdateBot2.UI
{
    class FileHippoDataGridItem : FileHippo.FileHippoDownload, INotifyPropertyChanged
    {
        private int _downloadProgress = 0;
        public int DownloadProgress
        {
            get
            {
                return this._downloadProgress;
            }
            set
            {
                this._downloadProgress = value;
                PropertyChanged(this, new PropertyChangedEventArgs("DownloadProgress"));
                PropertyChanged(this, new PropertyChangedEventArgs("IsDownloadComplete"));
            }
        }

        public Boolean IsDownloadComplete
        {
            get
            {
                return this.DownloadProgress >= 100;
            }
        }

        private Boolean _isChecked = true;
        public Boolean IsChecked
        {
            get
            {
                return this._isChecked;
            }
            set
            {
                this._isChecked = value;
                PropertyChanged(this, new PropertyChangedEventArgs("IsChecked"));
            }
        }

        private DateTime _whenStarted = DateTime.MinValue;
        public DateTime WhenStarted
        {
            get
            {
                return this._whenStarted;
            }
            set
            {
                this._whenStarted = value;
                PropertyChanged(this, new PropertyChangedEventArgs("WhenStarted"));
            }
        }

        /// <summary>
        /// Basic constructor carrying over properties.
        /// </summary>
        /// <param name="download"></param>
        public FileHippoDataGridItem(FileHippo.FileHippoDownload download)
            : base(download.Title, download.IconURI, download.Publisher, download.DownloadURI, download.Filename, download.Size, download.MD5CheckSum)
        {
            this.Version = download.Version;
        }

        /// <summary>
        /// Used to hook onto property changes.
        /// NOTE: Currently only supports DownloadProgress and IsChecked.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
